package cn.itsource._04direct;




import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class HelloRabbitmq {
    public static final String EXCHANGEDECLARE_DIRECT = "EXCHANGEDECLARE_DIRECT";
    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建连接
        ConnectionFactory factory = new ConnectionFactory();
        Connection connection = factory.newConnection();
        // 创建通道
        Channel channel = connection.createChannel();
        // 创建交换机，第三个参数为交换机持久化
        channel.exchangeDeclare(EXCHANGEDECLARE_DIRECT, BuiltinExchangeType.DIRECT);
        // 发送消息,routerKey为空因为只要绑定交换机的都发送消息，第三个参数消息消息持久化
        channel.basicPublish(EXCHANGEDECLARE_DIRECT, "direct1", null, "hello,direct1".getBytes());
        channel.basicPublish(EXCHANGEDECLARE_DIRECT, "error", null, "hello,error".getBytes());
        System.out.println("发送完成");
    }
}
